package com.share.servlet;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

public class demo5_refresh extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //页面定时刷新
//        test1(resp);
        //页面定时转跳（重定向）
        resp.setHeader("content-type", "text/html;charset=utf-8");
        resp.getWriter().write("3s后转跳");
        resp.setHeader("refresh","3;url=/sunxj-httpServletResponse/encoding");
    }

    private void test1(HttpServletResponse resp) throws IOException {
        //页面定时刷新
        resp.setHeader("content-type","text/html;charset=utf-8");
        resp.setIntHeader("refresh",1);
        resp.getWriter().println(new Random().nextInt() + "");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
